<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceDeleteGuest extends core {

    public function process() {
        $guest_id = intval($_POST['guest_id']);
        $user_id = intval($_POST['user_id']);
        $guest_id = $this->db->escape($guest_id);
        $data = $this->db->get_row("SELECT * FROM guests WHERE `guest_id`='$guest_id' AND `user_id`='$user_id'");
        if ($data) {
            $query = "DELETE FROM guests WHERE `guest_id`= '$guest_id' AND `user_id`='$user_id'";
            if ($this->db->query($query)===false) {
                
                $this->_JSONResponse(array('error' => 1, 'msg' => 'Contact has not been deleted, please save again'));
            } else {
                $query_delete_guest_in_guestevent = "DELETE FROM guest_event WHERE `guest_id`= '$guest_id' ";            
                $result = $this->db->query($query_delete_guest_in_guestevent);
                $this->_JSONResponse(array('error' => 0, 'msg' => 'Contact has been removed.'));
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Contact does not exist'));
        }
    }

}

$processor = new webServiceDeleteGuest();
$processor->process();
?>